// mircoApp/line_up_free/index/index.js
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgPath: app.globalData.imgPath,
    show: false,
    show_record: false,
    page: 1,
    total_page: 1,
    explain: "",
    statistic: {},
    list: [],
    has_many_free: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.getData();
  },
  getData(page = 1) {
    app._postNetWork({
      url: app.getNetAddresss('plugin.queue-order-free.frontend.controllers.center.index'),
      data: {
        page
      },
      success: resdata => {
        let {
          data,
          msg,
          result
        } = resdata.data;
        if (result !== 1) {
          return app.tips(msg);
        }
        let list = [];
        this.data.page = data.list.current_page;
        this.data.total_page = data.list.last_page;
        if (data.list.current_page == 1) {
          list = data.list.data;
        } else {
          list = this.data.list.concat(data.list.data);
        }
        this.setData({
          explain: data.explain,
          statistic: data.statistic,
          list
        })
      }
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },
  switch_handle(e) {
    let num = e.currentTarget.dataset.num;
    if (num == 1) {
      this.setData({
        show: true
      })
    } else if (num == 2) {
      this.setData({
        show: false
      })
    } else if (num == 3) {
      let item = e.currentTarget.dataset.item;
      this.setData({
        show_record: true,
        has_many_free: item.has_many_free
      });
    } else {
      this.setData({
        show_record: false
      });
    }
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    wx.setNavigationBarColor({
      frontColor: '#ffffff',
      backgroundColor: '#F15353',
      animation: {
        duration: 400,
        timingFunc: 'easeIn'
      }
    })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {
    if (this.data.page >= this.data.total_page) {
      return;
    }
    let page = this.data.page + 1;
    this.getData(page);
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})